<template>
  <div class="photoinfo-container">
    <!-- <h1>123</h1> -->
    <h3>{{photoinfo.title}}</h3>
    <p class="subtitle">
      <span>发表时间:{{ photoinfo.add_time | dateFormat }}</span>
      <span>点击:{{photoinfo.click}}次</span>
    </p>
    <hr />
    <div class="thumbs">
      <img class="preview-img" v-for="(item, index) in list" :src="item.src" height="100"  v-preview="item.src" :key="item.src"  >
    </div>
    <div class="content" v-html="photoinfo.content"></div>
     <coments  :id="id"></coments>
  </div>
</template>

<script>

import  coments from  '@/components/setcontents/coments.vue'

export default {
  name: "tupian",
  data() {
    return {
      id: this.$route.params.id,
      photoinfo: {},
      list: [] // 缩略图的数组
    };
  },
  created() {
    this.getphotinfo();
    this.getThumbs();
  },
  methods: {
    getphotinfo() {
      //获取新闻详情
      this.$http.get("getimageInfo/" + this.id).then(result => {
        if (result.body.status === 0) {
          //  console.log(result.body)
          //  Toast("获取新闻成功")
          this.photoinfo = result.body.message[0];
        } else {
          //  Toast("获取新闻失败")
        }
      });
    },
    getThumbs() {
      // 获取缩略图
      this.$http.get("getthumimages/" + this.id).then(result => {
        if (result.body.status === 0) {
          // 循环每个图片数据，补全图片的宽和高
          result.body.message.forEach(item => {
            item.w = 600;
            item.h = 400;
          });
          // 把完整的数据保存到 list 中
          this.list = result.body.message;
        }
      });
    }
  },
     components:{
       coments
   },
};
</script>
<style lang="scss" scoped>
.photoinfo-container {
  padding: 3px;
  h3 {
    color: #26a2ff;
    font-size: 15px;
    text-align: center;
    margin: 15px 0;
  }
  .subtitle {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
  }

  .content {
    font-size: 13px;
    line-height: 30px;
  }

  .thumbs{
    img{
      margin: 2px;
      box-shadow: 0 0 8px #999;
    }
  }
}
</style>
